package com.ruoyi.web.controller.estate.emergency;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.estate.emergency.EmergencySuppliesRecord;
import com.ruoyi.system.service.estate.emergency.IEmergencySuppliesRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应急物资记录Controller
 */
@RestController
@RequestMapping("/estate/emergency/supplies/record")
public class EmergencySuppliesRecordController extends BaseController {
    @Autowired
    private IEmergencySuppliesRecordService emergencySuppliesRecordService;

    /**
     * 查询应急物资记录列表
     */
    @PreAuthorize("@ss.hasPermi('estate:emergency:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmergencySuppliesRecord emergencySuppliesRecord) {
        startPage();
        List<EmergencySuppliesRecord> list = emergencySuppliesRecordService.selectEmergencySuppliesRecordList(emergencySuppliesRecord);
        return getDataTable(list);
    }

    /**
     * 导出应急物资记录列表
     */
    @PreAuthorize("@ss.hasPermi('estate:emergency:record:export')")
    @Log(title = "应急物资记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EmergencySuppliesRecord emergencySuppliesRecord) {
        List<EmergencySuppliesRecord> list = emergencySuppliesRecordService.selectEmergencySuppliesRecordList(emergencySuppliesRecord);
        ExcelUtil<EmergencySuppliesRecord> util = new ExcelUtil<EmergencySuppliesRecord>(EmergencySuppliesRecord.class);
        return util.exportExcel(list, "应急物资记录数据");
    }

    /**
     * 获取应急物资记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('estate:emergency:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId) {
        return success(emergencySuppliesRecordService.selectEmergencySuppliesRecordById(recordId));
    }

    /**
     * 新增应急物资记录
     */
    @PreAuthorize("@ss.hasPermi('estate:emergency:record:add')")
    @Log(title = "应急物资记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmergencySuppliesRecord emergencySuppliesRecord) {
        return toAjax(emergencySuppliesRecordService.insertEmergencySuppliesRecord(emergencySuppliesRecord));
    }

    /**
     * 修改应急物资记录
     */
    @PreAuthorize("@ss.hasPermi('estate:emergency:record:edit')")
    @Log(title = "应急物资记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmergencySuppliesRecord emergencySuppliesRecord) {
        return toAjax(emergencySuppliesRecordService.updateEmergencySuppliesRecord(emergencySuppliesRecord));
    }

    /**
     * 删除应急物资记录
     */
    @PreAuthorize("@ss.hasPermi('estate:emergency:record:remove')")
    @Log(title = "应急物资记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds) {
        return toAjax(emergencySuppliesRecordService.deleteEmergencySuppliesRecordByIds(recordIds));
    }
    
    /**
     * 获取物资分发记录
     */
    @GetMapping("/distribution")
    public AjaxResult getDistributionRecords() {
        List<EmergencySuppliesRecord> list = emergencySuppliesRecordService.selectDistributionRecords();
        return success(list);
    }
} 